package ooad.nextgen.gof.factory;

import ooad.nextgen.gof.PropertiesUtil;
import ooad.nextgen.gof.adapter.ITaxCalculatorAdapter;


public class TaxServiceFactory {
	private ITaxCalculatorAdapter taxCalculatorAdapter;
	
	public static TaxServiceFactory instance;
	/**
	 * 单例模式
	 * @return
	 */
	public static TaxServiceFactory getInstance(){
		if(instance ==null){
			instance = new TaxServiceFactory();
		}
		return instance;
	}
	
	/**
	 * 工厂模式
	 * @return
	 */
	public ITaxCalculatorAdapter getTaxCalculatorAdapter()  {
		if(taxCalculatorAdapter==null){
			String className = PropertiesUtil.getProperty("taxCalculator.class.name");
			try {
				taxCalculatorAdapter=(ITaxCalculatorAdapter) Class.forName(className).newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		return taxCalculatorAdapter;
	}
}
